/**
 * Created by soyomo on 17-8-28.
 */
angular.module('tribalc').controller('welfareInfoController',[
    '$scope',
    '$rootScope',
    'Api',
    'Alert',
    '$state',
    '$stateParams',
    function($scope,$rootscope,Api,Alert,$state,$stateParams) {
        $scope.goBacMorekWelfare = goBackMoreWelfare;
        $scope.getstatus = getstatus;
        $scope.getsex = getsex;
        $scope.getLocalTime = getLocalTime;
        $scope.infoHeadItems = ['发放日期','发放金额','发放人数','状态','发放理由','业务流水号'];
        $scope.infoListHeader = ['姓名','性别','部门','电话号码','金额'];
        function getLocalTime(nS) {
            var date = new Date(nS);
            Y = date.getFullYear() + '年';
            M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
            D = date.getDate() + '日';
            h = date.getHours() + ':';
            m = date.getMinutes()
            return Y + M + D ;
        }

        function getstatus(status) {
            return{'FINISHED':'正常','':''}[status];
        }

        function getsex(sex){
            return{'FEMALE':'女','MALE':'男'}[sex];
        }

        function goBackMoreWelfare(){
            $state.go('company.companymoreWelfare');
        }


        var welfareId = $stateParams.welfareId;

        getwelfareInfo(welfareId);

        function getwelfareInfo (welfareId){
            Api.getWelfareDetail(welfareId,function(info){
                $scope.welfareInfo = info.data;
            });

        }

        getWelFareList();

        function getWelFareList() {
            Api.getWelfareList(null,null,null,function (result) {
                var data = result.data.content;
                var welfareData = [];
                for (var i = 0;i<data.length;i++){
                    if(data[i].id === welfareId){
                        welfareData.push(data[i]);
                        $scope.welfareData = welfareData;
                        return;
                    }
                }
            });
        }
    }
]);